package com.stxx.stiot2.controller;

import com.stxx.framwork.domain.R;
import com.stxx.framwork.domain.model.PageQuery;
import com.stxx.framwork.domain.model.PageResult;
import com.stxx.framwork.tran.TranUtils;
import com.stxx.stiot2.domain.Driver;
import com.stxx.stiot2.service.DriverService;
import org.noear.solon.annotation.*;

import java.sql.SQLException;

@Controller
@Mapping("/driver")
public class DriverController {

    @Inject
    DriverService baseService;

    @Get
    @Mapping("/list")
    public PageResult<Driver> list(Driver bo, PageQuery pageQuery) throws SQLException {
        PageResult<Driver> r = baseService.pageList(bo,pageQuery);
        TranUtils.build().add("driverType").tran(r.getData());
        return r;
    }





    @Post
    @Mapping("")
    public R<Object> add(@Body Driver bo) throws SQLException {
        baseService.insert(bo);
        return R.ok("数据保存成功");
    }

    @Put
    @Mapping("")
    public R<Object> edit(@Body Driver bo) throws SQLException {
        baseService.update(bo);
        return R.ok("数据保存成功");
    }

    @Delete
    @Mapping("/{ids}")
    public R<Object> remove(@Path Integer[] ids) throws SQLException {
        baseService.deleteByIds(ids);
        return R.ok("数据删除成功");
    }
}
